< previous page page_18 next page >

Page 18
Puzzle 3
Poly Want a Cracker?
The windows graphical device interface (GDI) has far more graphics capability than is built into Visual Basic. One of the functions allows you to draw a polygon of as many lines as you wish in a single operation. The Polygon function is defined in the C documentation as follows:
BOOL Polygon(
HDC hdc,                // handle to device context
CONST POINT *lpPoints,  // pointer to polygon's vertices
int nCount              // count of polygon's vertices
);
The hdc parameter is the device context for the window on which the polygon will be drawn. The lpPoints parameter is a pointer to the first of a series of coordinates describing the points that are to be connected. The nCount parameter is the number of points.
Can you fix the following program to display the pattern shown in Figure P3-1?
' Poly Example Program
' Copyright © 1998 by Desaware Inc. All Rights Reserved

Option Explicit

Private Type POINTAPI
   X As Long
   Y As Long
End Type

Private Declare Function Polygon Lib "gdi32" (hdc As Long, _
lpPoint As POINTAPI, nCount As Long) As Long

' Function loads an array of points
Private Sub LoadPointArray(ByVal Width As Long, ByVal Height _
As Long, ByVal Increment As Integer, PointArray() As POINTAPI)
   Dim curidx As Integer
   ReDim PointArray((Height \ Increment) + 2)
   Do

 
< previous page page_18 next page >